﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/pages/master/WebForm.Master"
    CodeBehind="AreaEdit.aspx.cs" Inherits="BF.Web.pages.BaseSystem.AreaManagement.AreaEdit" %>

<%@ Register Src="~/pages/UserControls/SysAreaTree.ascx" TagName="SysAreaTree" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" language="javascript">
        $(function () {
            //关闭
            $("#<%=btnClose.ClientID %>").click(function () {
                winer.close();
                return false;
            });

            loadbody();

            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(loadbody);
        });

        function DoAdd() {
            $(parent.document).find(".x-window-header-text").html("行政区划新增");
            this.location.href = 'AreaEdit.aspx';
        }

        function UpatePage(sID) {
            $(parent.document).find(".x-window-header-text").html("行政区划修改");
            this.location.href = 'AreaEdit.aspx?sID=' + sID;
        }

        function loadbody() {
            $("#ctl00_ContentPlaceHolder1_AreaControl_sProvince").change(function () {
                $("#tishitd").html('*您添加的是<b>市级6位</b>行政区划编码');
            });

            $("#ctl00_ContentPlaceHolder1_AreaControl_sCity").change(function () {
                $("#tishitd").html('*您添加的是<b>县、区级6位</b>行政区划编码');
            });

            $("#ctl00_ContentPlaceHolder1_AreaControl_sCounty").change(function () {
                $("#tishitd").html('*您添加的是<b>镇级3位</b>行政区划编码');
            });

            $("#ctl00_ContentPlaceHolder1_AreaControl_sTwon").change(function () {
                $("#tishitd").html('*您添加的是<b>村级3位</b>行政区划编码');
            });
        };
    </script>
    <script type="text/javascript" language="javascript">        
        function validate() {
            var result = $("#aspnetForm").validate({
                rules: {
                    ctl00$ContentPlaceHolder1$sID: {//行政区划编码
                        required: true,
                        digits: true,
                        DigiMax: true
                    },
                    ctl00$ContentPlaceHolder1$sName: {//行政区划名称
                        required: true,
                        maxlength: 25
                    },
                    ctl00$ContentPlaceHolder1$iCountry: {//下设乡镇数
                        digits: true,
                        maxlength: 10
                    },
                    ctl00$ContentPlaceHolder1$iVillage: {//下设行政村数
                        digits: true,
                        maxlength: 10
                    },
                    ctl00$ContentPlaceHolder1$iGroup: {//下设组数
                        digits: true,
                        maxlength: 10
                    },
                    ctl00$ContentPlaceHolder1$iSumPop: {//辖区人口总数
                        digits: true,
                        maxlength: 10,
                        xiaquPanDing:true
                    }, ctl00$ContentPlaceHolder1$iAGRPop: {//农业人口总数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    }, ctl00$ContentPlaceHolder1$iWBHPop: {//五保户人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iPoorPop: {//贫困户人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iLodgePop: {//暂住人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iJoinDoor: {//新农合参合户数
                        digits: true,
                        maxlength: 10
                    },
                    ctl00$ContentPlaceHolder1$iJoinPop: {//新农合参合人数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iAdultPop: {//成年人人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iAdolescentPop: {//青少年人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iChildPop: {//儿童人口数
                        digits: true,
                        maxlength: 10,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$iOldPop: {//老年人人口数
                        digits: true,
                        maxlength: 10,
                        DuiBiChengNianRen: true,
                        DuiBixiaqu:true
                    },
                    ctl00$ContentPlaceHolder1$sXNHCode: {//新农合对照编码
                        maxlength: 50
                    },
                    ctl00$ContentPlaceHolder1$sXNHName: {//新农合对照名称
                        maxlength: 100
                    },
                    ctl00$ContentPlaceHolder1$sPostCode: {//邮政编码
                        zip: true
                    }
                },
                messages: {
                ctl00$ContentPlaceHolder1$iAGRPop: {//农业人口总数
                        DuiBixiaqu:"*农业人口数不能超过辖区人口总数"
                    }, ctl00$ContentPlaceHolder1$iWBHPop: {//五保户人口数
                        DuiBixiaqu:"*五保户人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iPoorPop: {//贫困户人口数
                        DuiBixiaqu:"*贫困人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iLodgePop: {//暂住人口数
                        DuiBixiaqu:"*暂住人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iJoinPop: {//新农合参合人数
                        DuiBixiaqu:"*新农合参合人数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iAdultPop: {//成年人人口数
                        DuiBixiaqu:"*成年人人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iAdolescentPop: {//青少年人口数
                        DuiBixiaqu:"*青少年人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iChildPop: {//儿童人口数
                        DuiBixiaqu:"*儿童人口数不能超过辖区人口总数"
                    },
                    ctl00$ContentPlaceHolder1$iOldPop: {//老年人人口数
                        DuiBixiaqu:"*老年人人口数不能超过辖区人口总数"
                    },
                },
                errorClass: "errorClass"
            });
            return result.form();
        }


        jQuery.validator.addMethod("DigiMax", function (value, element) {
            if ($("#cbxTree").val() != "请选择...") {//镇不为-1，添加的是村级3位
              
                return true;
            }

        }, "*行政编码位数错误");

        jQuery.validator.addMethod("DuiBixiaqu", function (value, element) {//各个字段值与辖区值进行对比
            var xiaquvalue = $("#ctl00_ContentPlaceHolder1_iSumPop").val();
            if (value.length == 0 || value == "" || value == "0")
            {
                return true;
            }
            else
            {
                if (xiaquvalue.length == 0 || xiaquvalue == "" || xiaquvalue == "0") {
                    return true;
                }
                else {
                    if (parseInt(xiaquvalue) <parseInt(value)) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
            }
        }, "*请填写辖区人口总数");

        jQuery.validator.addMethod("xiaquPanDing", function (value, element) {//辖区与成年人+儿童+青少年对比
            var chengnianrenvalue = $("#ctl00_ContentPlaceHolder1_iAdultPop").val(); //成年人
            var ertongvalue = $("#ctl00_ContentPlaceHolder1_iChildPop").val(); //儿童
            var qingshaonianvalue = $("#ctl00_ContentPlaceHolder1_iAdolescentPop").val(); //青少年
            var totalvalue = 0;
            if (value.length == 0 || value=="" ||value=="0") {
                return true;
            }
            else {
                if(chengnianrenvalue.length>0)
                {
                    totalvalue=totalvalue+parseInt(chengnianrenvalue);
                }
                if(ertongvalue.length>0)
                {
                    totalvalue=totalvalue+parseInt(ertongvalue);
                }
                if(qingshaonianvalue.length>0)
                {
                    totalvalue=totalvalue+parseInt(qingshaonianvalue);
                }
                if (parseInt(value) < totalvalue) {
                    return false;
                }
                else {
                    return true;
                }
            }
        }, "*成年人，儿童，青少年合计人口总数超过辖区人口总数");

        jQuery.validator.addMethod("DuiBiChengNianRen", function (value, element) {//老年人与成年人对比
            var chengnianrenvalue = $("#ctl00_ContentPlaceHolder1_iAdultPop").val(); //成年人
            if (value.length == 0 || value == "" || value == "0") {
                return true;
            }
            else {
                if (chengnianrenvalue.length == 0 || chengnianrenvalue == "" || chengnianrenvalue == "0") {
                    return true;
                }
                else {
                    if (parseInt(chengnianrenvalue) < parseInt(value)) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
            }
        }, "*老年人口总数不能超过成年人人口总数");

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="content01">
        <tbody>
            <tr style="height: 18px;">
                <td colspan="4">
                </td>
            </tr>
            <tr>
                <td align="right">
                    所属地区：
                </td>
                <td>
                    <uc1:SysAreaTree ID="SysAreaTree1" runat="server" />
                    <tll:DataTextBox ID="SysAreaTreeName" runat="server" Width="180"></tll:DataTextBox>
                </td>
                <td align="right">
                    <span style="color: Red">*</span>行政区划编码：
                </td>
                <td>
                    <tll:DataTextBox ID="sID" runat="server" Width="180"></tll:DataTextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <span style="color: Red">*</span>行政区划名称：
                </td>
                <td>
                    <tll:DataTextBox ID="sName" runat="server" Width="180" FeildName="sName" TableName="sys_Area"></tll:DataTextBox>
                </td>
                <td align="right">
                    
                </td>
                <td>
                    
                </td>
            </tr>
        </tbody>
    </table>
    <table width="100%" height="36" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr style="height: 18px;">
            <td colspan="4">
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnAdd" runat="server" OnClientClick="return DoAdd();" TabIndex="0"
                    Text="新增" class="btn04" Visible="false" />&nbsp;
                <asp:Button ID="btnSave" runat="server" TabIndex="0" Text="保存" class="btn04" OnClick="btnSave_Click"
                    OnClientClick="" />&nbsp;
                <asp:Button ID="btnClose" runat="server" TabIndex="0" Text="关闭" class="btn04" />
            </td>
        </tr>
    </table>
    <asp:UpdatePanel ID="Updatepanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
